package com.gx.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.gx.exception.DataBaseConnectFailedException;
import com.gx.str.ExMsgStr;

public class DBHplerSQLite {
	private static volatile Connection connection = null;

	private DBHplerSQLite() {
	}

	public static Connection getConnection() throws DataBaseConnectFailedException {
		String url = "jdbc:sqlite:///Users/hugo/SQLite/auth_rq.db3";
		String driver = "org.sqlite.JDBC";
		try {
			Class.forName(driver);
			if (connection == null || connection.isClosed()) {
				synchronized (DBHplerSQLite.class) {
					connection = DriverManager.getConnection(url);
				}
			}
		} catch (ClassNotFoundException e) {
			throw new DataBaseConnectFailedException(ExMsgStr.MSG_EX03, e);
		} catch (SQLException e) {
			throw new DataBaseConnectFailedException(ExMsgStr.MSG_EX02, e);
		}

		return connection;
	}

}
